home *** CD-ROM | disk | FTP | other *** search
/ Software 2000 / Software 2000 Volume 1 (Disc 1 of 2).iso / utilities / u286.dms / u286.adf / Misc / prefset.c / prefset.c
C/C++ Source or Header  |  1991-07-21  |  2KB  |  151 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "exec/types.h"
  4. #include "intuition/intuition.h"
  5. #include "intuition/preferences.h"
  6.  
  7. struct IntuitionBase    *IntuitionBase = NULL;
  8. struct IntuiMessage    *Message       = NULL;
  9. struct Window        *Window        = NULL;
  10. struct Preferences    Prefs;
  11.  
  12. UBYTE Filename[128];
  13.  
  14. WORD FilenamePts[] =
  15. {
  16.     0,0,
  17.     146,0,
  18.     146,9,
  19.     0,9,
  20.     0,0,
  21. };
  22.  
  23. struct Border        FilenameBdr =
  24. {
  25.     -1,-1,
  26.     1,0,
  27.     JAM1,
  28.     5,
  29.     FilenamePts,
  30.     NULL,
  31. };
  32.  
  33. struct StringInfo    FilenameStr =
  34. {
  35.     Filename,
  36.     NULL,
  37.     0,
  38.     128,
  39.     0,
  40.     0,0,0,0,0,
  41.     0,0,
  42.     0,
  43. };
  44.  
  45. struct Gadget        FilenameGad =
  46. {
  47.     NULL,
  48.     12,14,
  49.     144,11,
  50.     NULL,
  51.     STRINGCENTER|RELVERIFY,
  52.     STRGADGET,
  53.     (APTR)&FilenameBdr,
  54.     NULL,
  55.     NULL,
  56.     NULL,
  57.     (APTR)&FilenameStr,
  58.     NULL,
  59.     NULL,
  60. };
  61.  
  62. struct NewWindow    WindowDefs =
  63. {
  64.     236,113,
  65.     168,30,
  66.     2,1,
  67.     GADGETUP,
  68.     WINDOWDRAG|ACTIVATE,
  69.     &FilenameGad,
  70.     NULL,
  71.     "PrefSet v1.00",
  72.     NULL,
  73.     NULL,
  74.     168,30,
  75.     168,30,
  76.     WBENCHSCREEN,
  77. };
  78.  
  79. void CleanUp();
  80. void GetName();
  81.  
  82. main(int argc,char *argv[])
  83. {
  84.     FILE    *PrefsFile;
  85.  
  86.     if (((argc == 2) && (*argv[1] == '?')) || (argc > 2))
  87.     {
  88.         printf("PrefSet v1.00  Written in 1991 by Chris Simpson\n");
  89.         printf("Usage: %s [prefsfile]\n",argv[0]);
  90.         CleanUp();
  91.     }
  92.  
  93.     IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",LIBRARY_VERSION);
  94.     if (!IntuitionBase)
  95.     {
  96.         printf("Can't open intuition.library\n");
  97.         CleanUp();
  98.     }
  99.  
  100.     if (argc == 1)
  101.     {
  102.         GetName();
  103.     }
  104.     else
  105.     {
  106.         strcpy(Filename,argv[1]);
  107.     }
  108.  
  109.     if (*Filename)
  110.     {
  111.         if(!(PrefsFile=fopen(Filename,"r")))
  112.         {
  113.             printf("Can't open \"%s\" for input\n",Filename);
  114.             CleanUp();
  115.         }
  116.  
  117.         fread((void *)&Prefs,sizeof(Prefs),1,PrefsFile);
  118.         fclose(PrefsFile);
  119.  
  120.         SetPrefs(&Prefs,sizeof(Prefs),1);
  121.     }
  122.  
  123.     CleanUp();
  124. }
  125.  
  126. void GetName()
  127. {
  128.     Window=(struct Window *)OpenWindow(&WindowDefs);
  129.     if (!Window)
  130.     {
  131.         printf("Can't open requester window\n");
  132.         CleanUp();
  133.     }
  134.  
  135.     ActivateGadget(&FilenameGad,Window,NULL);
  136.  
  137.     while(!(Message=(struct IntuiMessage *)GetMsg(Window->UserPort)))
  138.     {
  139.     }
  140.     ReplyMsg((struct Message *)Message);
  141.  
  142.     CloseWindow(Window);
  143. }
  144.  
  145. void CleanUp()
  146. {
  147.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  148.     exit(0);
  149. }
  150.  
  151.